//
//  UIPlaceHolderTextField.m
//  SMealUserSide
//
//  Created by apple on 2018/2/22.
//  Copyright © 2018年 yaozhengzheng. All rights reserved.
//

#import "UIPlaceHolderTextField.h"

@implementation UIPlaceHolderTextField
// 控制placeHolder的位置，左右缩20，但是光标位置不变

-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+self.placeHolderOffset, bounds.origin.y, bounds.size.width-self.placeHolderOffset, bounds.size.height);//更好理解些
    return inset;
}


// 修改文本展示区域，一般跟editingRectForBounds一起重写
- (CGRect)textRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+self.placeHolderOffset, bounds.origin.y, bounds.size.width-self.placeHolderOffset, bounds.size.height);//更好理解些
    return inset;
}

// 重写来编辑区域，可以改变光标起始位置，以及光标最右到什么地方，placeHolder的位置也会改变
-(CGRect)editingRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+self.placeHolderOffset, bounds.origin.y, bounds.size.width-self.placeHolderOffset, bounds.size.height);//更好理解些
    return inset;
}

- (void)setPlaceHolderFont:(UIFont *)placeHolderFont
{
    _placeHolderFont = placeHolderFont;
    [self setValue:placeHolderFont forKeyPath:@"_placeholderLabel.font"];
}

- (void)setPlaceHolderColor:(UIColor *)placeHolderColor
{
    _placeHolderColor = placeHolderColor;
   [self setValue:_placeHolderColor forKeyPath:@"_placeholderLabel.textColor"];
}

@end
